package tw.edu.tku.im.maze;

import org.json.JSONException;
import org.json.JSONObject;

public class Member {
   String userID;
   String name;
   
   static Member parse(JSONObject jsonObj) throws JSONException {
      String userID = jsonObj.getString("userID");
      String name = jsonObj.getString("name");
      return new Member(userID, name);
   }
   
   //-------------------------------------------------------
   public Member(String userID, String name) {
      this.userID = userID;
      this.name = name;
   }
   
   //-------------------------------------------------------
   public String getUserID() {
      return userID;
   }

   public void setUserID(String userID) {
      this.userID = userID;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
   
   //-------------------------------------------------------
   public String toString() {
      StringBuilder ans = new StringBuilder("{ \"userID\" : \"");
      ans.append(this.userID).append("\", ").append("\"name\" : \"")
         .append(this.name).append("\" }");
      return ans.toString();
   }

   //-------------------------------------------------------
   public String toJSONString() throws JSONException {
      JSONObject member = new JSONObject();
      member.put("userID", this.userID);
      member.put("name", this.name);
      return member.toString();
   }
}
